// pages/order/order.js
import {listOrder} from "../../utils/request";

Page({

  /**
   * 页面的初始数据
   */
  data: {
    current: 'dealing',
    order_status: {}, // 订单状态对应
    tab_list: [
      {key: 'no_deal', title: "未处理"},
      {key: 'deal', title: "已受理"},
      {key: 'dealing', title: "进行中"},
      {key: 'done', title: "已完成"}
    ],
    order_list: [
      {
        'id': 1,
        'user_id': 1,
        'employee_id': 2,
        'order_time': 1586500366,
        'appointment_time': 1586586766,
        'status': 0,
        'service_id': 1,
        'service_name': '家装',
        'sub_service_id': 1,
        'sub_service_name': '更换电灯',
        'is_negotiated': 0,
        'coupon_id': null,
        'service_cost': 2000,
        'product_cost': 1888,
        'reduced_cost': 0,
        'original_cost': 3888,
        'actual_price': 3888,
        'address': '广东省清远市清城区黄金海岸xxxx'
      }
    ]
  },

  handleChange ({ detail }) {
    this.setData({
      current: detail.key
    });
    let current_status = this.data.order_status.get(detail.key)
    listOrder(
        {
          order_status: current_status,
          page: 1,
          limit: 8
        },
        res => {
          console.log(res)
        }
    )
  },

  gotoDetail(e) {
    console.log(e)
    ///pages/order_detail/order_detail?order
    wx.navigateTo({
      url: '/pages/order_detail/order_detail?order_id=' + e.currentTarget.dataset.order_id
    })
  },


  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
      this.setData({
        order_status : new Map([
          ['no_deal', 0], ['deal', 1], ['dealing', 2], ['done', 3]
        ])
      })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  }
})